package com.three.iot.commons.enums;

import com.three.iot.commons.exceptions.BusinessException;

import java.util.Objects;

/**
 * @author luiz
 * @Title: ResultCode
 * @ProjectName iot
 * @Description: TODO
 * @date 2019-04-03 16:00
 */
public enum ResultCode {
    COMMON_PARAM_NULL("1001", "参数为空"),
    COMMON_PARAM_INVALID("1002", "参数不合法"),
    COMMON_DATA_EXISTS("1003", "数据已存在"),
    COMMON_DATA_NOT_EXISTS("1004", "数据不存在"),
    COMMON_ORDER_SOURCE_ERROR("1005", "数据来源方不存在"),
    COMMON_QUERY_ERROR("1006", "数据执行SQL查询错误"),
    COMMON_UNVALID_URL("1007", "非法链接"),

    //基础资料 1100-1199
    USER_PASS_NOT_EQUAL("1100", "两次密码不一致"),
    USER_OLD_PASS_ERROR("1101", "原始密码错误"),
    USER_NOT_EXISTS("1102", "用户不存在"),
    PASS_NOT_STRONG("1103", "密码只能输入字母、数字、特殊符号"),
    USER_HAS_LOCK("1104", "账户被锁定,禁止登录"),
    PASS_OVERDUE("1105", "密码已过期,需要修改"),
    PSS_NEED_MODIFY("1106", "密码需要修改"),
    USER_REGISTER_ERROR("1107", "用户注册异常"),
    USER_HAS_EXISTS("1108", "账号已存在"),
    PASS_CANNOT_CONTAINS_ACCOUNT("1109", "密码不能包含账号"),

    // 设备操作 1200
    DEVICE_NOT_EXISTS("1200", "设备不存在"),
    ATTR_NOT_EXISTS("1201", "设备属性不存在"),



    SUCCESS("200", "操作成功"),
    FAIL("500", "系统异常,请联系系统管理员"),
    CHANNEL_ERROR("501", "渠道异常"),
    USER_NO_LOGGED_IN("510", "用户未登录"),
    FOR_UNAUTHORIZED("511", "用户未授权"),
    USERNAME_OR_PASS_ERR("512", "用户名或密码错误");

    String code;
    String message;

    ResultCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static final ResultCode matching(String code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (Objects.equals(resultCode.getCode(), code)) return resultCode;
        }
        return null;
    }
}
